local hx__luoyi = fk.CreateSkill {
  name = "hx__luoyi",
}

Fk:addPoxiMethod{
  name = "hx__luoyi__type",
  card_filter = function(to_select, selected, data)
    if table.contains(data[2], to_select) then return true end
    local n = Fk:getCardById(to_select).type
    for _, id in ipairs(data[2]) do
      if Fk:getCardById(id).type == n then return false end
    end
    return true
  end,
  feasible = function(selected)
    return true
  end,
}

hx__luoyi:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__luoyi.name) and player.phase == Player.Draw
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cids = room:getNCards(player.maxHp)
    room:moveCardTo(cids, Card.Processing, nil, fk.ReasonJustMove, self.name, nil, true, player)
    local function clearRemain(ids)
      ids = table.filter(ids, function(id) return room:getCardArea(id) == Card.Processing end)
      room:moveCardTo(ids, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, self.name, nil, true, player)
    end
    local cards = {}
    for _, id in ipairs(cids) do
      local card = Fk:getCardById(id)
      if card then
        table.insert(cards, id)
      end
    end
    if #cards > 0 then
      local get = room:askToArrangeCards(player, {
        skill_name = hx__luoyi.name,
        card_map = {cards},
        prompt = "#hx__luoyi_select",
        free_arrange = false,
        box_size = 0,
        max_limit = {4, 4},
        min_limit = {0, 1},
        poxi_type = "hx__luoyi__type",
      })[2]
      if #get == 0 then return end
      local choice = room:askToChoice(player, {
        choices = {"hx__luoyi_fou","hx__luoyi_get"},
        skill_name = hx__luoyi.name,
        prompt = "#hx__luoyi_get",
      })
      if choice == "hx__luoyi_get" then
        room:addPlayerMark(player, "@@hx__luoyi")
        room:moveCardTo(get, Player.Hand, player, fk.ReasonJustMove, self.name, "", true, player)
        cards = table.filter(cards, function(id) return room:getCardArea(id) == Card.Processing end)
        room:moveCards({
          ids = cards,
          toArea = Card.DiscardPile,
          moveReason = fk.ReasonPutIntoDiscardPile,
        })
        clearRemain(cids)
        data.phase_end = true
      end
    end
    clearRemain(cids)
  end,
})

hx__luoyi:addEffect(fk.DamageCaused, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__luoyi") > 0 and
    data.card and (data.card.trueName == "slash" or data.card.name == "duel") and data.by_user
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player:broadcastSkillInvoke("hx__luoyi")
    player.room:notifySkillInvoked(player, "hx__luoyi","offensive")
    data:changeDamage(1)
  end,
})

hx__luoyi:addEffect(fk.TurnStart, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@@hx__luoyi") ~= 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@@hx__luoyi", 0)
  end,
})






return hx__luoyi